﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DAL;
using BLL;

namespace QLTTTH
{
    public partial class frmThongTinChungChi : DevExpress.XtraEditors.XtraForm
    {
        public frmThongTinChungChi()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public void FillControl(ChungChi chngchi)
        {
            this.txtMaChungChi.Text = chngchi.MaChungChi.ToString();
            this.loupMonHoc.EditValue = chngchi.MaMH;
            this.txtNoiCap.Text = chngchi.NoiCap;
            this.txtThoiHan.Text = chngchi.ThoiHan;
            this.txtTenChungChi.Text = chngchi.TenChungChi;
        }



        public delegate void SendData(ChungChi chungchi);

        public SendData sendData;
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (sendData != null)
            {
                var vResult = new ChungChiManager().Validate(LayChungChi());
                if (vResult.Valid)
                {
                    sendData(LayChungChi());
                    DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    XtraMessageBox.Show(vResult.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public ChungChi LayChungChi()
        {
            ChungChi chungchi = new ChungChi();

            if (!txtMaChungChi.Text.ToString().Equals(""))
            {
                chungchi.MaChungChi = int.Parse(txtMaChungChi.Text.ToString());
            }
            chungchi.MaMH = int.Parse(loupMonHoc.EditValue.ToString());
            chungchi.TenChungChi = txtTenChungChi.Text;
            chungchi.NoiCap = txtNoiCap.Text;
            chungchi.ThoiHan = txtThoiHan.Text;
            return chungchi;
        }

        private void frmThongTinChungChi_Load(object sender, EventArgs e)
        {
            var dsmh = MonHocManager.LayDanhSachMonHoc();
            if (dsmh.Success)
            {
                loupMonHoc.Properties.DataSource = dsmh.Result;
                loupMonHoc.Properties.ValueMember = "MaMH";
                loupMonHoc.Properties.DisplayMember = "TenMH";

            }

        }
    }
}